package com.dementors.ui.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.Button;

import com.dementors.R;
import com.dementors.base.BaseFragment;
import com.dementors.ui.activity.LoginActivity;
import com.dementors.view.MyImageView;
import com.dementors.view.MyItemView;
import com.dementors.view.MyTextView;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2015/12/1 0001.
 */
public class FragmentMine extends BaseFragment implements View.OnClickListener {
    private String[] order = {"待付款", "待收货", "待评价", "我的返现", "我的售后"};
    private int[] orderid = {R.drawable.ic_my_daifukuan, R.drawable.ic_my_yiishouhuo, R.drawable.ic_my_daipinglun, R.drawable.ic_my_daifanxian, R.drawable.ic_my_shouhou};
    private MyImageView mivOrder1, mivOrder2, mivOrder3, mivOrder4, mivOrder5;
    private List<MyImageView> orders = new ArrayList<>();
    private List<MyTextView> moneys=new ArrayList<>();
    private MyItemView mv,mv1,mv2,mv3,mv4,mv5,mv6;
    private MyTextView mtvMoney1, mtvMoney2, mtvMoney3, mtvMoney4;
    private String[] textMoney1 = {"0", "0", "0", "0.00"};
    private String[] textMoney2 = {"现金券", "品牌红包", "贝壳", "余额"};
    private Button btn1,btn2;


    @Override
    protected int provideContentViewId() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void initViews() {
        initOrderView();//初始化全部订单下方5个控件
        initMoneyView();//初始化我的钱包与下方4个控件
        initList();//初始化下方列表中所有控件
        initButton();//初始化登录注册2个按钮
    }

    private void initButton() {
        btn1= (Button) view.findViewById(R.id.btn_mine_login1);
        btn2= (Button) view.findViewById(R.id.btn_mine_login2);
    }

    private void initList() {
        mv1= (MyItemView) view.findViewById(R.id.mv_list1);
        mv1.setImage(R.drawable.my_ico_collection);
        mv1.setText("我的喜欢");
        mv2= (MyItemView) view.findViewById(R.id.mv_list2);
        mv2.setImage(R.drawable.ic_c2c_my_shop);
        mv2.setText("我的小店");
        mv3= (MyItemView) view.findViewById(R.id.mv_list3);
        mv3.setImage(R.drawable.ic_personal_invite);
        mv3.setText("好友优惠");
        mv4= (MyItemView) view.findViewById(R.id.mv_list4);
        mv4.setImage(R.drawable.my_ico_promise);
        mv4.setText("正品保证");
        mv5= (MyItemView) view.findViewById(R.id.mv_list5);
        mv5.setImage(R.drawable.ic_c2c_beibeishop);
        mv5.setText("分享赚钱");
        mv6= (MyItemView) view.findViewById(R.id.mv_list6);
        mv6.setImage(R.drawable.my_ico_service);
        mv6.setText("客服与帮助");
    }

    private void initMoneyView() {
        mv = (MyItemView) view.findViewById(R.id.mv_money);
        mv.setImage(R.drawable.ic_personal_wallet);
        mv.setText("我的钱包");
        mtvMoney1 = (MyTextView) view.findViewById(R.id.mtv_money1);
        mtvMoney2 = (MyTextView) view.findViewById(R.id.mtv_money2);
        mtvMoney3 = (MyTextView) view.findViewById(R.id.mtv_money3);
        mtvMoney4 = (MyTextView) view.findViewById(R.id.mtv_money4);
        moneys.add(mtvMoney1);
        moneys.add(mtvMoney2);
        moneys.add(mtvMoney3);
        moneys.add(mtvMoney4);
        for(int i=0;i<moneys.size();i++){
            moneys.get(i).setText1(textMoney1[i]);
            moneys.get(i).setText2(textMoney2[i]);
        }
    }

    private void initOrderView() {
        mivOrder1 = (MyImageView) view.findViewById(R.id.miv_order1);
        mivOrder2 = (MyImageView) view.findViewById(R.id.miv_order2);
        mivOrder3 = (MyImageView) view.findViewById(R.id.miv_order3);
        mivOrder4 = (MyImageView) view.findViewById(R.id.miv_order4);
        mivOrder5 = (MyImageView) view.findViewById(R.id.miv_order5);
        orders.add(mivOrder1);
        orders.add(mivOrder2);
        orders.add(mivOrder3);
        orders.add(mivOrder4);
        orders.add(mivOrder5);
        for (int i = 0; i < orders.size(); i++) {
            orders.get(i).setText(order[i]);
            orders.get(i).setImageView(orderid[i]);
        }
    }

    @Override
    protected void initData() {
        resigenerListener();//初始化监听器
    }

    private void resigenerListener() {
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_mine_login1:
                Intent intent=new Intent(getActivity(), LoginActivity.class);
                startActivity(intent);

                break;
            case R.id.btn_mine_login2:
                break;
        }
    }
}
